package com.solming.leetcode.question;

public class Fib509 {

    public static int fib(int n) {
        if (n == 0) {
            return 0;
        }
        if (n == 1) {
            return 1;
        }

        int pre = 0;
        int cur = 1;
        for (int i = 2; i <= n; i++) {

            int tmp = cur;
            cur = cur + pre;
            pre = tmp ;

        }
        return cur;
    }

    public static void main(String[] args) {
        System.out.println(fib(4));
    }
}
